package com.hdy.DBUtils;

import java.sql.*;
import java.util.ResourceBundle;

public class JDBC {
    private static ResourceBundle bundle=ResourceBundle.getBundle("com.hdy.Resources.jdbc");
    private static String driver= bundle.getString("driver");
    private  static  String url=bundle.getString("url");
    private static  String user= bundle.getString("user");
    private  static  String password= bundle.getString("password");

    static {
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    public static Connection getConnection() throws SQLException {
        Connection connection= DriverManager.getConnection(url,user,password);
        return connection;
    }
    public static void close(Connection conn,PreparedStatement ps, ResultSet rs) {
        if(rs!=null){
            try {
                rs.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
            if(ps!=null){
                try {
                    ps.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
            if(conn!=null){
                try {
                    conn.close();
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
